package com.example.mybaties.testone.aop.java_dynamic_proxy;

import com.example.mybaties.testone.aop.common.ForumServiceImpl;
import com.example.mybaties.testone.aop.common.PerformanceMonitor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class PerformanceInvoktionHandler implements InvocationHandler {

    private Logger logger = LogManager.getLogger(this.getClass());

    private Object target;

    public PerformanceInvoktionHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
//        logger.debug("proxy" + proxy);
        PerformanceMonitor.begin(method.getName());
        Object result = method.invoke(target, args);
        PerformanceMonitor.end();
        return result;
    }


}
